<script type="text/javascript">
$(document).ready(function(){

	$('form').submit(function(e){
		e.preventDefault();
		var data = '&pass=' + $(this).find('.pass').val() +
				   '&new_email=' + $(this).find('.new_email').val() + 
				   '&new_email2=' + $(this).find('.new_email2').val();
			$.ajax({ 
				url: '<?php echo base_url()."changeProfile/changeEmail/"?>',
				type: 'POST', 
				data: data,
				success: function(data) {
					obj = eval("("+data+")");
					console.log(obj);
				     	if (obj == "Ok"){
				     	$('.changeProf h1').html('Zmena e-mailu úspešná!');
				     	$('.forma').empty();
				     	$(function() {
      setTimeout(function() {
        $('#facebox').hide();
							$('.warn_comments').hide();
							$('.warn_thumbs').hide();
							$('.facebox_overlayBG').hide();
							$('.facebox_overlay').hide();
    }, 2000);
});
						}
						else if (obj == "bad_old_pw"){
							  	if($('.reg_error').html != ""){
								$('.reg_error').fadeOut(500);
								$('.reg_error').fadeIn(500);
							}
					$('.reg_error').html('<span style="font-size:10px; color:red;">Incorrect current password!</span>');
					  }
					  else {
					    $('.reg_error').html("");
					    if (obj['new_email'] == ""){
					  		$('.email_error').html('');							
							}
						 if (obj['new_email2']==""){
								$('.email_error2').html('');
							}
					  	if (obj['new_email'] != ""){
					  		  	if($('.email_error').html != ""){
								$('.email_error').fadeOut(500);
								$('.email_error').fadeIn(500);
							}
					  		$('.email_error').html('<span style="font-size:10px; color:red;">' + obj['new_email'] + '</span>');							
							}
						 if (obj['new_email2']!=""){
						 	  	if($('.email_error2').html != ""){
								$('.email_error2').fadeOut(500);
								$('.email_error2').fadeIn(500);
							}
								$('.email_error2').html('<span style="font-size:10px; color:red;">' + obj['new_email2'] + '</span>');
							}
					  }
					}
				});
		});  
	
});
</script>




<div class="reg_div">
	<h1>Zmena e-mailu</h1>
	<ul style="list-style: none;text-align: center;padding:3px;" class='forma'>
		<?php echo form_open('changeProfile/submit');
		?>
		<li class="reg_error">
		</li>
		<li>	
			<?php echo form_input(array('type' => 'password', 'name' => 'pass', 'class' => 'pass', 'placeholder' => 'Password', 'autocomplete' => 'off')); ?>
		</li>	
		<li>
			<?php echo form_input(array('type' => 'text', 'name' => 'new_email', 'class' => 'new_email', 'placeholder' => 'Old E-mail', 'autocomplete' => 'off')); ?>
		</li>
		<li class="email_error">
		</li>	
		<li>
			<?php echo form_input(array('type' => 'text', 'name' => 'new_email2', 'class' => 'new_email2', 'placeholder' => 'New E-mail', 'autocomplete' => 'off')); ?>
		</li>
		<li class="email_error2">
		</li>	
		<li>
			<?php echo form_submit(array('type' => 'submit','value' => 'Potvrď zmeny!', 'class' => 'reg_button')); ?>
		</li>
		<?php echo form_close(); ?>

	</ul>

</div>